﻿#region 命名空间

using System;
using System.Web;
using System.Configuration;
using System.Collections.Generic;
using WinnerCMS.Common;
using System.IO;
using System.Linq;
using WinnerCMS.Model;
using WinnerCMS.BLL.CacheHepler;
using WinnerCMS.BLL.Rights;

#endregion

namespace WinnerCMS.BLL
{
    public class RightsCheck : System.Web.UI.Page
    {
        /// <summary>
        /// 是否已经登录
        /// </summary>
        public static bool IsLogined
        {
            get { return HttpContext.Current.User.Identity.IsAuthenticated; }
        }

        #region 遍历管理员拥有的权力

        /// <summary>
        /// 遍历管理员拥有的权力
        /// </summary>
        /// <param name="rightsCode"></param>
        /// <returns></returns>
        public static bool HasRight(string rightsCode)
        {
            return HasRight(rightsCode, UserManage.Current.RightCodes, false);
        }

        /// <summary>
        /// 遍历管理员拥有的权力
        /// </summary>
        /// <param name="rightsCode"></param>
        /// <param name="modelId"></param>
        /// <returns></returns>
        public static bool HasRight(string rightsCode, byte modelId)
        {
            rightsCode = string.Format("{0}{1}", modelId, rightsCode);

            return UserManage.Current.RightCodes.Any(x => x == rightsCode);
        }

        /// <summary>
        /// 遍历管理员拥有的权力
        /// </summary>
        /// <param name="rightsCode">要使用的功能需要的权限</param>
        /// <param name="powerstr">管理员拥有的权限字串</param>
        /// <param name="checkModel">是否检测模型权限</param>
        /// <returns></returns>
        internal static bool HasRight(string rightsCode, IList<string> powerstr, bool checkModel)
        {
            if (checkModel)
            {
                rightsCode = string.Format("{0}{1}", HttpContext.Current.Request["ModelId"], rightsCode);
            }

            return UserManage.Current.RightCodes.Any(x => x == rightsCode);
        }

        #endregion
    }
}